<?php defined('InNcPHP') or exit('Access Invalid!');?>
<style>
    /*.limitDl .nav_title{ border-bottom: 1px solid #f5f5f5; margin: 5px;}*/
    /*.limitDl .nav{border:1px solid #ddd;height:620px;margin-left:92px;overflow:auto;margin-top: -18px; padding: 5px;}*/
    .limitDl .line{ white-space: nowrap; line-height: 30px; border-bottom: 1px solid #f5f5f5; padding: 5px 0; font-size: 0.7rem}
    .limitDl .line1{ line-height: 50px; font-size: 1.0rem;font-weight: 1rem;color: #0D93BF;}
    .limitDl .nav_child{ margin-left: 20px;}
    .limitDl{ margin-bottom: 5px;}
    .limitDl dd{ padding-left: 15px;}
</style>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['nc_limit_manage'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <form id="add_form" method="post">
        <input type="hidden" name="form_submit" value="ok" />
        <table class="table tb-type2 nobdb">
            <tbody>
            <tr class="noborder">
                <td colspan="2" class="required"><label class="validation" for="admin_name"><?php echo $lang['gadmin_name'];?>:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" id="group_name" maxlength="40" name="group_name" class="txt"></td>
                <td class="vatop tips"></td>
            </tr>
            <?php if($output['admin_info']['id']==1): ?>
            <tr class="noborder">
                <td colspan="2" class="required"><label class="validation" for="admin_name">是否属于超级管理权限组:</label></td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <select name="is_super_group">
                        <option value="0" >否</option>
                        <option value="1">是</option>
                    </select>
                </td>
                <td class="vatop tips" style="color:red;font-size: 15px;">*ps:属于敏感的权限组请选择'是',设置完成之后,该权限组的成员以及该组权限只能由超级管理员添加编辑！其他管理员无权操作！</td>
            </tr>
            <?php endif;  ?>
            <tr>
                <td colspan="2"><table class="table tb-type2 nomargin">
                        <thead>
                        <!--                <tr class="space">-->
                        <!--                  <th> <input id="limitAll" id="limitAll" value="1" type="checkbox">&nbsp;&nbsp;--><?php //echo $lang['admin_set_limt'];?><!--</th>-->
                        <!--                </tr>-->
                        </thead>
                        <tbody>
                        <!-- 属于超级管理员添加不验证权限 -->
                        <?php if($output['admin_info']['id']==1){ ?>
                        <?php foreach((array)$output['limit'] as $key_a => $val_a) { ?>
                            <dl class="limitDl">
                                <dt class="line1"><?php echo $val_a['name'];?></dt>
                                <?php
                                foreach($val_a['child'] as $key_b => $val_b){
                                    ?>
                                    <dd>
                                        <label class="line"><input class="pcate" id="limit<?php echo $key_a.$key_b;?>" type="checkbox" onclick="selectLimit('limit<?php echo $key_a.$key_b;?>')"><b><?php echo $val_b['name'];?></b>&nbsp;&nbsp;</label>
                                        <br>
                                        <div class="nav_child">
                                            <?php
                                            foreach($val_b['child'] as $val_c){
                                                ?>
                                                <?php if(isset($val_c['params'])){?>
                                                    <label class="line"><input nctype="limit"  class="limit<?php echo $key_a.$key_b;?>" <?php if($val_c['check']){?> rel="check"<?php }?>type="checkbox"  name="permission[]" value="<?php echo $val_c['op'].'.'.$val_c['act'].'.'.$val_c['params'];?>"

                                                        ><?php echo $val_c['name'];?>&nbsp;</label>
                                                <?php }else{?>
                                                    <label class="line">
                                                        <input nctype="limit"  class="limit<?php echo $key_a.$key_b;?>" <?php if($val_c['check']){?> rel="check"<?php }?>type="checkbox" name="permission[]"    value="<?php echo $val_c['op'].'.'.$val_c['act'];?>"><?php echo $val_c['name'];?>&nbsp;</label>
                                                <?php }?>
                                                <?php
                                            }
                                            ?>
                                        </div>
                                    </dd>
                                    <?php
                                }
                                ?>
                            </dl>
                        <?php } ?>

                        <?php }else{ ?>
                            <!-- 不属于超级管理员验证权限 -->
                            <?php foreach((array)$output['limit'] as $key_a => $val_a) { ?>
                                <dl class="limitDl">
                                    <dt class="line1"><?php echo $val_a['name'];?></dt>
                                    <?php
                                    foreach($val_a['child'] as $key_b => $val_b){
                                        ?>
                                        <dd>
                                            <label class="line"><input class="pcate" id="limit<?php echo $key_a.$key_b;?>" type="checkbox" onclick="selectLimit('limit<?php echo $key_a.$key_b;?>')"><b><?php echo $val_b['name'];?></b>&nbsp;&nbsp;</label>
                                            <br>
                                            <div class="nav_child">
                                                <?php
                                                foreach($val_b['child'] as $val_c){
                                                    ?>
                                                    <?php if(isset($val_c['params'])){?>
                                                        <label class="line"><input nctype="limit"  class="limit<?php echo $key_a.$key_b;?>" <?php if($val_c['check']){?> rel="check"<?php }?>type="checkbox"  name="permission[]" value="<?php echo $val_c['op'].'.'.$val_c['act'].'.'.$val_c['params'];?>"
                                                                <?php if(in_array($val_c['op'].'.'.$val_c['act'].'.'.$val_c['params'],$output['ginfo']['limits'])){ echo 'checked';}  ?>
                                                            ><?php echo $val_c['name'];?>&nbsp;</label>
                                                    <?php }else{?>
                                                        <label class="line">
                                                            <!--                                                        --><?php //if(in_array($val_c['action'].'.'.$val_c['mod'],$output['ginfo']['limits'])){ echo 'checked';}  ?>
                                                            <input nctype="limit"  class="limit<?php echo $key_a.$key_b;?>" <?php if($val_c['check']){?> rel="check"<?php }?>type="checkbox" name="permission[]"   <?php if(in_array($val_c['op'].'.'.$val_c['act'],$output['ginfo']['limits'])){ echo 'checked';}else{echo $output['admin_info']['id']==1?'':"disabled";}  ?> value="<?php echo $val_c['op'].'.'.$val_c['act'];?>"><?php echo $val_c['name'];?>&nbsp;</label>
                                                    <?php }?>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                        </dd>
                                        <?php
                                    }
                                    ?>
                                </dl>
                            <?php } ?>

                        <?php  }?>
                        </tbody>
                    </table></td>
            </tr>
            </tbody>
            <tfoot>
            <tr class="tfoot">
                <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span><?php echo $lang['nc_submit'];?></span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>
</div>
<script>
    function selectLimit(name){
        if($('#'+name).attr('checked')) {
            $('.'+name).attr('checked',true);
        }else {
            $('.'+name).attr('checked',false);
        }
    }
    $(document).ready(function(){
        //按钮先执行验证再提交表单
        $("#submitBtn").click(function(){
            if($("#add_form").valid()){
                $("#add_form").submit();
            }
        });

        $('#limitAll').click(function(){
            $('input[type="checkbox"]').attr('checked',$(this).attr('checked') == 'checked');
        });

        $("#add_form").validate({
            errorPlacement: function(error, element){
                error.appendTo(element.parent().parent().prev().find('td:first'));
            },
            rules : {
                group_name : {
                    required : true,
                    remote	: {
                        url :'index.php?act=admin&op=ajax&branch=check_group_name',
                        type:'get',
                        data:{
                            group_name : function(){
                                return $('#group_name').val();
                            }
                        }
                    }
                }
            },
            messages : {
                group_name : {
                    required : '<?php echo $lang['nc_none_input'];?>',
                    remote	 : '<?php echo $lang['admin_add_admin_not_exists'];?>'
                }
            }
        });
    });
</script>